package com.jcfk.eam.controller.equ;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.web.domain.*;
import com.jcfk.eam.domain.dto.base.EamAssetTypeDTO;
import com.jcfk.eam.domain.dto.main.*;
import com.jcfk.eam.domain.query.main.EamAssetInfoQuery;
import com.jcfk.eam.enums.AssetKind;
import com.jcfk.eam.service.equ.EquStatisticsPlanRepairOrderService;
import com.jcfk.eam.service.equ.EquStatisticsPointCheckOrderService;
import com.jcfk.eam.service.equ.EquStatisticsRepairOrderService;
import com.jcfk.eam.service.equ.EquStatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 设备统计分析
 *
 */
@Api(tags = {"设备统计分析"})
@RestController
@RequestMapping("equStatistics")
public class EquStatisticsController {

    @Autowired
    private EquStatisticsRepairOrderService equStatisticsRepairOrderService;
    @Autowired
    private EquStatisticsPlanRepairOrderService equStatisticsPlanRepairOrderService;
    @Autowired
    private EquStatisticsPointCheckOrderService equStatisticsPointCheckOrderService;
    @Autowired
    private EquStatisticsService equStatisticsService;

    /**
     * 故障维修数据统计
     */
    @ApiOperation("故障维修数据统计")
    @PostMapping("/queryEamRepairOrderList")
    public RetResult<EquStatisticsRepairOrderDTO> queryRepairOrderList(@RequestBody EquStatisticsDTO query) {
        return RetResult.ok(equStatisticsRepairOrderService.queryRepairOrderList(query));
    }

    /**
     * 计划检修数据统计
     */
    @ApiOperation("计划检修数据统计")
    @PostMapping("/queryPlanRepairOrdeList")
    public RetResult<EquStatisticsPlanRepairOrderDTO> queryPlanRepairOrdeList(@RequestBody EquStatisticsDTO query) {
        return RetResult.ok(equStatisticsPlanRepairOrderService.queryPlanRepairOrdeList(query));
    }

    /**
     * 设备巡检数据统计
     */
    @ApiOperation("设备巡检数据统计")
    @PostMapping("/queryPointCheckOrderList")
    public RetResult<EquStatisticsPointCheckOrderDTO> queryPointCheckOrderList(@RequestBody EquStatisticsDTO query) {
        return RetResult.ok(equStatisticsPointCheckOrderService.queryPointCheckOrderList(query));
    }

    /**
     * mttr 数据统计
     */
    @ApiOperation("mttr 数据统计")
    @PostMapping("/mttr/statistics")
    public RetPage<EquMttrStatisticsDTO> mttrStatistics(@RequestBody ReqPageParam<EquStatisticsDTO> requestParam) {
        // 设置默认排序
        if (requestParam.getSort().getOrderItem() == null) {
            ReqSortParam<EquStatisticsDTO> sortParam = new ReqSortParam();
            sortParam.setColumn("assetCode");
            sortParam.setOrderBy("asc");
            requestParam.setSort(sortParam);
        }

        DataPage<EquMttrStatisticsDTO> page = new DataPage<EquMttrStatisticsDTO>((long) requestParam.getCurrent(),
            (long) requestParam.getSize(),
            requestParam.getSort().getOrderItem(),
            EquMttrStatisticsDTO.class);
        page = equStatisticsService.mttrStatistics(page, requestParam.getData());
        return new RetPage<>(page);
    }
    /**
     * mttr 数据统计
     */
    @ApiOperation("mtbf 数据统计")
    @PostMapping("/mtbf/statistics")
    public RetPage<EquMtbfStatisticsDTO> mtbfStatistics(@RequestBody ReqPageParam<EquStatisticsDTO> requestParam) {
        // 设置默认排序
        if (requestParam.getSort().getOrderItem() == null) {
            ReqSortParam<EquStatisticsDTO> sortParam = new ReqSortParam();
            sortParam.setColumn("assetCode");
            sortParam.setOrderBy("asc");
            requestParam.setSort(sortParam);
        }

        DataPage<EquMtbfStatisticsDTO> page = new DataPage<EquMtbfStatisticsDTO>((long) requestParam.getCurrent(),
            (long) requestParam.getSize(),
            requestParam.getSort().getOrderItem(),
            EquMtbfStatisticsDTO.class);
        page = equStatisticsService.mtbfStatistics(page, requestParam.getData());
        return new RetPage<>(page);
    }
}
